package com.tl.branchmanagementdemo.listener;

import com.tl.branchmanagementdemo.dao.BranchDao;
import com.tl.branchmanagementdemo.listener.event.UserRegistrationEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @author Administrator
 */
@Component
@Slf4j
public class ApplicationContextEventListener {

    @Autowired
    private BranchDao branchDao;

    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    @Async
    public void smsNotificationEvent(UserRegistrationEvent event) {
        log.info("进入了smsNotificationEvent方法");
        Long aLong = branchDao.selectCount(null);
        log.info("aLong={}", aLong);
        log.info("发送短信通知，恭喜用户 " + event.getUsername() + " 注册成功！");
    }

}
